package com.jinke.uang.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jinke.uang.R;
import com.jinke.uang.common.GlideImageLoader;
import com.jinke.uang.bean.ImgsListData;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 补充资料的适配器
 */
public class OtherAdapter extends RecyclerView.Adapter<OtherAdapter.ImgListViewHolder> {
    private OnItemClickListener onItemClickListener;
    private Context context;
    private List<ImgsListData.ImgPathListBean> data;

    public OtherAdapter(Context context, List<ImgsListData.ImgPathListBean> data) {
        this.context = context;
        this.data = data;
    }

    @NonNull
    @Override
    public ImgListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_img_list_layout, parent,
                false);
        return new ImgListViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final ImgListViewHolder holder, int position) {
        switch (position) {

            case 0:
                holder.tv.setText(context.getString(R.string.custom_auth_page_shuika));
                break;
            case 1:
                holder.tv.setText(context.getString(R.string.custom_auth_page_baoxiandan));
                break;
            case 2:
                holder.tv.setText(context.getString(R.string.custom_auth_page_hukouben));
                break;
            case 3:
                holder.tv.setText(context.getString(R.string.custom_auth_page_cunzhe));
                break;
            case 4:
                holder.tv.setText(context.getString(R.string.custom_auth_page_mingpain));
                break;
            case 5:
                holder.tv.setText(context.getString(R.string.custom_auth_page_jiashizheng));
                break;
            case 6:
                holder.tv.setText(context.getString(R.string.custom_auth_page_chepai));
                break;
            case 7:
                holder.tv.setText(context.getString(R.string.custom_auth_page_yongtupingzheng));
                break;
            case 8:
                holder.tv.setText(context.getString(R.string.custom_auth_page_xinyongka));
                break;
            case 9:
                holder.tv.setText(context.getString(R.string.custom_auth_page_gongzuozhengming));
                break;
            default:
                break;
        }


        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onClick(holder.itemView, holder.getLayoutPosition());
                }
            }
        });

        if (null != data.get(position).getNativeFileUri()) {
            GlideImageLoader.LoadImage(context, data.get(position).getNativeFileUri(), holder
                    .ivPhoto);
            return;
        }

        if (!TextUtils.isEmpty(data.get(position).getImagePathUrl())) {
            GlideImageLoader.LoadImage(context, data.get(position).getImagePathUrl(), holder
                    .ivPhoto);
        }

    }

    @Override
    public int getItemCount() {
        return data.size();
    }


    @Override
    public long getItemId(int position) {
        return position;
    }

    public class ImgListViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv)
        ImageView iv;
        @BindView(R.id.tv)
        TextView tv;
//        @BindView(R.id.mark)
//        TextView mark;
        @BindView(R.id.iv_photo)
        ImageView ivPhoto;


        public ImgListViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


    public interface OnItemClickListener {
        void onClick(View view, int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
}
